package com.fanbuchi.fukua.activity.base;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.widget.Toast;

import com.fanbuchi.fukua.config.AppConfig;
import com.umeng.analytics.MobclickAgent;

import de.greenrobot.event.EventBus;

/**
 * Created by killerzhangsan on 2015/5/19.
 */
public class BaseFragment extends Fragment {

    protected int page=1;
    protected int next_page=1;
    protected int page_size=16;
    public static final String mIdata= AppConfig.mIdata;
    public static final int requestCode=AppConfig.requestCode;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(BaseFragment.class.getName());
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(BaseFragment.class.getName());
    }

    /**
     * @title 启动activity
     * @param clazz 启动的activityclass
     */
    public void startActivity(Class<? extends Activity> clazz) {
        Intent intent  = new Intent(getActivity(),clazz);
        startActivityForResult(intent, 0);
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    public  void display(String content){
        if (!isDetached() && getActivity()!=null && !getActivity().isFinishing() && !getActivity().isDestroyed()){
            Toast.makeText(getActivity(),content,Toast.LENGTH_SHORT).show();
        }
    }

    public  void display(int stringsRes){
        if (stringsRes>0){
            display(getResources().getString(stringsRes));
        }
    }

}
